<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
    	$this->assign("title","留言本系统登录");
        $this->display();
	}
	    public function notice(){
    	$this->assign("title","留言本系统");
		$id=I('uid');
		$user = D("liuyan");
		$userinfo = $user->where("id='$id'")->find();
		$this->assign("username",$userinfo['username']);
		$this->assign("password",$userinfo['password']);
        $this->display();
		
	}
		public function handle(){
			$data =array(
			'username' => $username = I('username'),	
				'con' => $con = I('con'),
				'time'=> time(),
			'password'=>$password = I('password'),
				);
			$user = D("liuyan");
			$user->data($data)->add(); 
			$userinfo = $user->where("username ='$username'")->find();
			$this->success('发布成功',U("Index/message",array('uid' => $userinfo["id"])));
		}
		public function relogin(){
			$id=I('id');
			$this->redirect("notice",array('uid' => $id));
		}
		public function message(){
			import('ORG.Util.Date');
			$id =I('uid');
			$user = D("liuyan");
			$userinfo = $user->where("id='$id'")->find();
			$username =$userinfo['username'];
			 $this->assign("title","留言本系统");
			 $this->assign('user',$user->where("username=$username")->select())->display();
		}
	 public function login(){
			$username = $_POST['username'];
			$passwd = $_POST['password'];
			$user = D("liuyan");
			//$User->where('id=8')->find();这里的where 语句要注意一下，如果是其他字段的话后面一定要有单引号
			$userinfo = $user->where("username ='$username'")->find();
			if(!empty($userinfo)){
			if($userinfo['password'] == $passwd){
			$this->success('登陆成功！',U("Index/notice/",array('uid' => $userinfo["id"]),''));
			}else{
			$this->error('密码出错，请重新输入！',U("Index/index"));
			}}
			else{
			$this->error('用户名不存在！请注册',U("Register/index"));
			}

			}


}
?>
